set dotenv-load

run: (cmd "runserver")

cmd *args:
  python ./manage.py {{args}}

test: (cmd "test tests")

build:
  npx tailwindcss -m -i ./static-origin/style/tailwind.css -o ./static/style/tailwind.min.css
  ./node_modules/.bin/esbuild "./static-origin/script/**/*.ts" "./static-origin/script/**/*.js" --bundle --minify --splitting --format="esm" --outdir=./static/script
  cp -rT ./node_modules/@ag-grid-community/styles/ ./static/style/ag-grid-community
  cp ./node_modules/@wangeditor-next/editor/dist/css/style.css ./static/style/wang-editor-next.min.css

# specify `DJANGO_SUPERUSER_PASSWORD` environment variable
create-super-user: \
  (cmd "createsuperuser" "--no-input")

shell: (cmd "shell")

exec file:
  python ./manage.py shell -c "`cat {{file}}`"

db: (cmd "dbshell")

loaddata: (cmd "loaddata" "initial.yaml" "test/user.yaml") # TODO "test/project.yaml"

init-trans: (cmd "makemessages" "-l" "zh_CN")

trans: (cmd "makemessages" "-a")

[confirm('This is a very dangerous operations. Know what this operation does first! Continue? [Y/N]')]
renew-db: && loaddata create-super-user
  mysql -u $BY6PMS_MYSQL_USER --password=$BY6PMS_MYSQL_PASSWORD -e "drop database $BY6PMS_MYSQL_DATABASE_NAME; create database $BY6PMS_MYSQL_DATABASE_NAME;"
  python ./manage.py migrate

# delete all existing migrations, empty existing database, and make new migrations and migrate.
[confirm('This is a very dangerous operations. Know what this operation does first! Continue? [Y/N]')]
renew-migrations: && renew-db
  fd -p "apps/migrations/.*\.py" -E __init__.py . -x rm {}
  fd -p "apps/migrations/.*\.pyc" . -x rm {}
  python ./manage.py makemigrations

update-release-repo:
  ./00_script/script/update_release_repo.sh
